<?php
class UtilityService extends BaseService
{

    private $redisObj;
    static private $_instance = NULL;

    private function  __construct()
    {
        $this->redisObj = Config::getRedisClient();
    }

    private function  __clone()
    {
    }

    static public function getInstance()
    {
        if (is_null(self::$_instance) || !isset(self::$_instance)) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }

    public function arrayBackward($arr, $offset, $count)
    {
        $result = array();
        for ($i = count($arr) - 1 - $offset; $i >= 0 && count($result) < $count; $i--) {
            if (isset($arr[$i])) {
                array_push($result, $arr[$i]);
            }
        }
        return $result;
    }

    public function arrayForward($arr, $offset, $count)
    {
        $result = array();
        for ($i = $offset; $i < count($arr) && count($result) < $count; $i++) {
            if (isset($arr[$i])) {
                array_push($result, $arr[$i]);
            }
        }
        return $result;
    }
}